<script setup>
import { ref, computed } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { ElConfigProvider } from 'element-plus';
import { User, Service } from '@element-plus/icons-vue';

const router = useRouter();
const route = useRoute();
const activeIndex = ref('1');

// 计算当前路由是否应该以弹窗形式展示
const isDialogRoute = computed(() => {
  return route.meta.isDialog;
});

// 计算当前主路由（非弹窗路由）
const mainRoute = computed(() => {
  if (isDialogRoute.value) {
    return '/hotel-search'; // 默认返回酒店搜索页
  }
  return route.path;
});

const handleSelect = (key) => {
  if (key === '1') {
    router.push('/hotel-search');
  }
};

// 返回首页
const goHome = () => {
  router.push('/hotel-search');
};

// 关闭弹窗
const closeDialog = () => {
  router.push(mainRoute.value);
};
</script>

<template>
  <el-config-provider>
    <div class="app-container">

      <main class="app-content">
        <!-- 主路由视图 -->
        <router-view v-slot="{ Component }" v-if="!isDialogRoute">
          <transition name="fade" mode="out-in">
            <keep-alive :include="['HotelSearch']">
              <component :is="Component" />
            </keep-alive>
          </transition>
        </router-view>
        
        <!-- 弹窗路由视图 -->
        <el-dialog
          v-if="isDialogRoute"
          v-model="isDialogRoute"
          :fullscreen="true"
          :show-close="true"
          :destroy-on-close="true"
          @close="closeDialog"
          custom-class="route-dialog"
        >
          <router-view v-slot="{ Component }">
            <transition name="fade" mode="out-in">
              <component :is="Component" />
            </transition>
          </router-view>
        </el-dialog>
      </main>
    </div>
  </el-config-provider>
</template>

<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Noto Sans SC', 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  background-color: #f5f7fa;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background-color: #409EFF;
  color: white;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.logo {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.logo-img {
  height: 40px;
  margin-right: 10px;
}

.logo h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.main-menu {
  flex: 1;
  margin-left: 40px;
  border-bottom: none;
}

.user-actions {
  display: flex;
  gap: 15px;
}

.user-button {
  color: white;
  font-size: 14px;
  display: flex;
  align-items: center;
}

.user-button .el-icon {
  margin-right: 5px;
}

.app-content {
  flex: 1;
  background-color: #f5f7fa;
}

.app-footer {
  background-color: #2c3e50;
  color: #ffffff;
  padding: 40px 0 20px;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.footer-section {
  width: 22%;
  min-width: 200px;
  margin-bottom: 20px;
}

.footer-section h3 {
  font-size: 16px;
  margin-bottom: 15px;
  font-weight: 500;
  color: #ffffff;
}

.footer-section ul {
  list-style: none;
  padding: 0;
}

.footer-section li {
  margin-bottom: 8px;
  font-size: 14px;
  color: #b3c0d1;
  cursor: pointer;
}

.footer-section li:hover {
  color: #409EFF;
}

.social-icons {
  display: flex;
  gap: 15px;
}

.social-icons .el-icon {
  font-size: 24px;
  cursor: pointer;
}

.copyright {
  max-width: 1200px;
  margin: 20px auto 0;
  padding: 20px 20px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  font-size: 14px;
  color: #b3c0d1;
}

/* 弹窗样式 */
.route-dialog {
  margin: 0 !important;
  display: flex;
  flex-direction: column;
}

.route-dialog .el-dialog__header {
  padding: 15px 20px;
  margin: 0;
  border-bottom: 1px solid #ebeef5;
}

.route-dialog .el-dialog__body {
  flex: 1;
  padding: 0;
  overflow-y: auto;
}

.route-dialog .el-dialog__close {
  font-size: 20px;
  color: #606266;
}

/* 页面过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>